<?php

load_control('datatable');

class message_list extends datatable
{
	var $count;

	function message_list($id, $user_id, $link_id=0, $return_zero=true, $form_name='0', $return_to='')
	{
		global $GO_CONFIG, $GO_SECURITY, $GO_MODULES, $GO_LANGUAGE, $GO_THEME, $GO_LINKS;

		$this->datatable($id, false, $form_name);
		$this->set_attribute('style','width:100%;margin-bottom:20px;margin-top:0px;');
		$return_to = !empty($return_to) ? $return_to : $_SERVER['PHP_SELF'];

		require($GO_LANGUAGE->get_language_file('message'));

		require_once($GO_MODULES->modules['message']['class_path']."message.class.inc");
		$message = new message();

		if($this->task == 'delete')
		{
			foreach($this->selected as $delete_message_id)
			{
				$delete_message_id = str_replace('4:', '', $delete_message_id);
				$message->delete_message($delete_message_id);
			}
		}
		// 错误回馈
		if (isset($feedback))
		{
			$p = new html_element('p', $feedback);
			$p->set_attribute('class','Error');
			$this->add_html_element($p);
		}

		$this->add_column(new table_heading($lang_message['title'], 'title'));
		$this->add_column(new table_heading($lang_message['sender'], 'send_uid'));
		$this->add_column(new table_heading($lang_message['send_time'], 'send_date'));
		$this->add_column(new table_heading($lang_message['operation']));
		$th = new table_heading('&nbsp;');
//		$this->add_column($th);
		// 获得短消息总数
		$this->count = $message->get_messages($user_id, $this->sort_index, $this->sql_sort_order, $this->start, $this->offset);
		// 设置分页
		$this->set_pagination($this->count);
		// 遍历当前用户短消息内容
		if($this->count > 0)
		{
			while($message->next_record()) {
				$row = new table_row('4:'.$message->f('id'));
				// 双击表格某一行，显示该行的信息  【该行可删除】
//				$row->set_attribute('ondblclick', "javascript:window.location.href='" . $GO_MODULES->modules['message']['url'] . 'message.php?message_id=' . $message->f('id') . '&return_to='.urlencode($return_to) . "';");
				$id = $message->Record['id'];
				$title = $message->Record['title'];
				$content = $message->Record['content'];
				$sender = 'allan';
				$send_time = $message->Record['send_date'];
				$operation = '回复 转发';
				if($content != '')
				{
					$img = new image('plus_node');
					$img->set_attribute('style','border:0px;margin-right:5px;');
					$img->set_attribute('onclick','javascript:toggle_msg(this);');
					$img->set_attribute('id',$id);


					$cell = new table_cell($img->get_html().htmlspecialchars($title));
					$cell->set_attribute('valign','top');
					$div = new html_element('div', text_to_html($content));
					$div->set_attribute('class', 'description');
					$div->set_attribute('style','display:none');
					$div->set_attribute('id',$id.'_div');
					$cell->add_html_element($div);
				}else
				{
					$img = new image('blank');
					$img->set_attribute('style','border:0px;margin-right:5px;');
					$cell = new table_cell($img->get_html().htmlspecialchars($title));
				}
				$row->add_cell($cell);

				$cell = new table_cell($sender);
				$cell->set_attribute('valign','top');
				$row->add_cell($cell);

				$cell = new table_cell($send_time);
				$cell->set_attribute('valign','top');
				$row->add_cell($cell);

				$cell = new table_cell($operation);
				$cell->set_attribute('valign','top');
				$row->add_cell($cell);

				$this->add_row($row);
			}
		}else
		{
			if($return_zero)
			{
				$row = new table_row();
				$cell = new table_cell($no_no_message);
				$cell->set_attribute('colspan','99');
				$row->add_cell($cell);
				$this->add_row($row);
			}else
			{
				$this->innerHTML = '';
				return false;
			}
		}

		$this->outerHTML .= '<script type="text/javascript">
		function toggle_msg(img)
		{
			
			if(document.getElementById(img.id+"_div").style.display=="none")
			{
				img.src="'.$GO_THEME->images['min_message'].'";
				document.getElementById(img.id+"_div").style.display="block";
			}else
			{
				img.src="'.$GO_THEME->images['plus_message'].'";
				document.getElementById(img.id+"_div").style.display="none";
			}
		}
		
		
		</script>';
	}
}
?>